package com.carassistant.beta.common.dialog;


import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.carassistant.beta.R;
/***
 * 对话框
 * @author james
 *
 */

public class MessageDialog extends BaseDialog {
	LayoutInflater inflater;
	LinearLayout ll;
	Button setButton,cancelButton;
	/**
	 * 构造方法
	 * @param context
	 */
	public MessageDialog(Context context) {
		super(context);
		this.context = context;
		this.inflater = LayoutInflater.from(context);

		ll = (LinearLayout)inflater.inflate(R.layout.viewjar_message_dialog_super_view, null);
		titleView = (TextView)ll.findViewById(R.id.dialog_title);
		setButton = (Button)ll.findViewById(R.id.dialog_set);
		cancelButton = (Button)ll.findViewById(R.id.dialog_cancel);

		setContentView(ll);
		setNegativeButton("确定", null);
	}
	public MessageDialog(Context context,String message){
		this(context);
		setMessage(message);
	}
	public MessageDialog setTitle(String title) {
		if (!TextUtils.isEmpty(title) && null != titleView) {
			titleView.setText(title);
		}
		return this;
	}
	public MessageDialog setMessage(String message) {
		TextView tv = (TextView)ll.findViewById(R.id.content_tv);
		tv.setText(message);
		return this;
	}

	public MessageDialog setPositiveButton(CharSequence text, OnDialogButtonClickListener listener) {
		setButton.setVisibility(View.VISIBLE);
		setButton.setTag(listener);
		setButton.setText(text);
		setButton.setOnClickListener(mListener);
		return this;
	}
	public MessageDialog setNegativeButton(CharSequence text, OnDialogButtonClickListener listener) {
		cancelButton.setVisibility(View.VISIBLE);
		cancelButton.setTag(listener);
		cancelButton.setText(text);
		cancelButton.setOnClickListener(mListener);
		return this;
	}
	public MessageDialog setPositiveButton(int textId, OnDialogButtonClickListener listener) {
		String text = context.getResources().getString(textId);
		setPositiveButton(text, listener);
		return this;
	}
	public MessageDialog setNegativeButton(int textId, OnDialogButtonClickListener listener) {
		String text = context.getResources().getString(textId);
		setNegativeButton(text, listener);
		return this;
	}
}
